//
//  NJYBleService.h
//  NJYBLESDK
//
//  Created by Michael on 2022/7/26.
//

#import <Foundation/Foundation.h>

#import <CoreBluetooth/CoreBluetooth.h>
#import <NJYBLESDK/NJY_PublicEnum.h>
#import <NJYBLESDK/NJYAsyncCallback.h>
#import <NJYBLESDK/NJY_DailInfoModel.h>
#import <NJYBLESDK/NJY_ContactModel.h>
#import <NJYBLESDK/NJY_AReceiptCodeModel.h>
#import <NJYBLESDK/NJY_TimeSetModel.h>
#import <NJYBLESDK/NJY_AlarmModel.h>
#import <NJYBLESDK/NJY_NotifModel.h>
#import <NJYBLESDK/NJY_AllDaySwitchModel.h>
#import <NJYBLESDK/NJY_FemaleHealthModel.h>
#import <NJYBLESDK/NJY_WeatherModel.h>
#import <NJYBLESDK/NJY_UserInfoModel.h>
#import <NJYBLESDK/NJY_Peripherial.h>
#import <NJYBLESDK/NJY_SysDataModel.h>
#import <NJYBLESDK/NJY_SleepModel.h>
#import <NJYBLESDK/NJY_SportRecordModel.h>
#import <NJYBLESDK/NJY_EcgModel.h>
#import <NJYBLESDK/NJY_DeviceConfigModel.h>
#import <NJYBLESDK/NJY_DeviceFunModel.h>
#import <NJYBLESDK/NJY_TypeMedicModel.h>
#import <NJYBLESDK/NJY_GameModel.h>



#define KSCANPERIPHERA_NOTIF                             @"scan_peripheral"                                 //扫描到设备
#define KPERIPHERIALCONNECTED_NOTIF                      @"peripherial_connected"                           //连接上设备
#define KBLEDISCONNECTED_NOTIF                           @"bleDisconnected"                                 //设备断开
#define KBLECONNECTED_NOTIF                              @"NotificationBleConnected"                                 //设备断开
#define KBLEOPENTAKEPHOTO_NOTIF                              @"NotificationOpenTtakePhoto"                                 //拍照打开


@protocol NJYBleServiceDelegate <NSObject>

@optional

/// Description
/// @param state
///  CBManagerStateUnknown = 0,
///  CBManagerStateResetting,
///  CBManagerStateUnsupported,
///  CBManagerStateUnauthorized,
///  CBManagerStatePoweredOff,
///  CBManagerStatePoweredOn,
/// @param des des description
- (void)centralManagerDidUpdateState:(NSInteger)state des:(NSString *_Nullable)des;

@end

@class NJY_Peripherial;

NS_ASSUME_NONNULL_BEGIN
@interface NJYBleService : NSObject

@property (nonatomic, weak) id<NJYBleServiceDelegate> delegate;
@property (nonatomic, strong) NSMutableArray *bleModals;            //设备ModelList
@property (nonatomic, strong) CBPeripheral *myPeripherial;     //连接设备
@property (nonatomic, assign) BOOL isBinded;                      //是否连接过
@property (nonatomic, assign) NSInteger batteryLevel;              //电量
@property (nonatomic, assign) BOOL isPostConnected;
@property (nonatomic, assign) BOOL isSystem_Type;
@property (nonatomic, assign) BOOL isNewConnected;
@property (nonatomic, strong) NSArray<NJY_GameModel*>* gameList;
@property (nonatomic, assign) CGSize dailSize;                     //表盘大小

+ (instancetype)sharedInstance;

/// 测试
-(NSString *)testString;

/// 扫描
- (void)scan;

/// 停止扫描
- (void)stopScan;


/// 连接BLE
/// @param peripherial peripherial description
- (void)connect:(CBPeripheral *)peripherial;

/// 重连设备
- (void)reconnect;

/// 设备断连
- (void)unbind;

/// 获取当前绑定的外设
/// @param uuidString  uuidString
- (CBPeripheral *)retrievePeripheralWith:(NSString *)uuidString;

/// 写入指令
/// @param type 功能ID
/// @param value 数据参数
//- (void)sendCommand:(NJY_CommandType)type data:(id _Nullable)value;

#pragma mark - ****************发送设置
/**
 *
 *指令函数-(void)send;
 */

/// 查找手环 EVT_TYPE_ALERT_FIND_WATCH
-(void)sendAlertFindWatch;

/// 拍照 EVT_TYPE_TAKE_PHOTO NSInteger isVideoDial = [[kUserDefaults objectForKey:AARuiyuCustomVideoDial]integerValue
/// @param isOpen 状态 0=打开；0=关闭
-(void)sendTakePhoto:(NSInteger)isOpen;

/// 抬腕亮屏 EVT_TYPE_RAISE_WRIST
/// @param model 只需要设置model isOn
-(void)sendRaiseWrist:(NJY_TimeSetModel *) model;

/// 久坐提醒 EVT_TYPE_LONG_SIT
/// @param model model description
-(void)sendLongSit:(NJY_TimeSetModel *) model;

/// 喝水提醒 EVT_TYPE_DRINK_WATER
/// @param model model description
-(void)sendDrinkWater:(NJY_TimeSetModel *) model;

///注意一次要设置4次；如果空白闹钟值为0
/// 设置闹钟  EVT_TYPE_ALARM
/// @param model model description
-(void)sendAlarm:(NJY_AlarmModel *) model;

/// 设置时间格式 EVT_TYPE_TIME_MODE
/// @param note  0:24h制，1：12h制
-(void)sendTimeMode:(NSInteger) note;

/// 设置温度格式 EVT_TYPE_TEMP_UNIT
/// @param note 0:摄氏度制，1：华氏度制（手表默认摄氏度制）
-(void)sendTempUnit:(NSInteger) note;

/// 设置单位制度 EVT_TYPE_UNIT_SYSTEM
/// @param note 0:公制，1：英制（手表默认公制）
-(void)sendUnitSystem:(NSInteger) note;

/// 设置消息通知 EVT_TYPE_NOTIFICATIONS
/// @param model model description
-(void)sendNotif:(NJY_NotifModel *)model;

/// 设置全天测量开关 EVT_TYPE_ALL_DAY_FALG
/// @param model model description
-(void)sendAllDayFalg:(NJY_AllDaySwitchModel *) model;

/// 女性健康 EVT_TYPE_WOMEN_HEALTH
/// @param model model description
-(void)sendWomenHealth:(NJY_FemaleHealthModel *) model;

/// 设置语言 EVT_TYPE_LANGUAGE
/// @param language language description
-(void)sendLanguage:(NJY_Language) language;

/// 设置日期、时间  EVT_TYPE_DATE_TIME
/// @param curInterval 当前时间戳包含时区
-(void)sendCurDateTime:(NSInteger)curInterval;

/// 实时天气 EVT_TYPE_REAL_TIME_WEATHER
/// @param model model description
-(void)sendRealTimeWeather:(NJY_WeatherModel *) model;

/// 目标步数 EVT_TYPE_TARGET_STEP
/// @param size 目标步数
-(void)sendTargetStep:(NSInteger)size;

/// 用户信息 EVT_TYPE_USER_INFO
/// @param model model description
-(void)sendUserInfo:(NJY_UserInfoModel*) model;

#pragma mark - **************** callback函数有响应返回值
/**
 *
 *函数有返回值
 */
/// 固件OTA升级
/// @param peripheral 设备peripheral对象
/// @param otaType otaType = 0 普通升级；otaType = 1 静默升级
/// @param path 升级包路径
/// @param callback callback  result 1
- (void)sendDeviceOta:(CBPeripheral *)peripheral otaType:(EVT_OTA_TYPE)otaType path:(NSString*)path callback:(NJYAsyncCallback *)callback;


/// 系统表盘
/// @param path 表盘路径
/// @param data data nil
/// @param type type 1
/// @param callback callback  result       OTA_TYPE_SUCCESS            = 0,//升级成功
- (void)sendDialInstall:(NSString *)path data:(NSData*)data type:(NSInteger)type callback:(NJYAsyncCallback *)callback;

/// 自定义表盘
/// @param dailInfo 表盘信息Model
/// @param type 0
/// @param callback callback   result       OTA_TYPE_SUCCESS            = 0,//升级成功
- (void)sendCustomDialInstall:(NJY_DailInfoModel *)dailInfo type:(NSInteger)type callback:(NJYAsyncCallback *)callback;

/// 删除OTAclearCallBack
-(void)clearOTACallBack;

/// 拍照 旧函数sendRuiyuInstruction
/// @param value true false
/// @param callback callback  result  0 = /* 关闭 */;1 =/* 拍照 */ ; 2=/* 打开 */
- (void)sendTakePhoto:(id)value callback:(NJYAsyncCallback *)callback;

/// 联系人
/// @param contactList NJY_ContactModel list
/// @param callback callback  result       OTA_TYPE_SUCCESS            = 0;成功
- (void)sendContact:(NSArray<NJY_ContactModel *>*)contactList callback:(NJYAsyncCallback *)callback;

/// 同步数据
/// @param callback callback result NJY_SysDataModel
- (void)sendSysData:(NJYAsyncCallback *)callback;

/// 睡眠数据
/// @param callback callback result NJY_SleepModel
- (void)sendSleepData:(NJYAsyncCallback *)callback;

/// 运动记录
/// @param callback callback result NJY_SportRecordModel
- (void)sendTrainingData:(NJYAsyncCallback *)callback;

/// 闹钟
/// @param callback callback result list<NJY_AlarmModel*>
-(void) getAlarmData:(NJYAsyncCallback *)callback;

/// 同步24小时步数
/// @param callback callback list<NJY_SysDataModel>
- (void)sendSysHourData:(NJYAsyncCallback *)callback;

/// 同步24小时Kcal
/// @param callback callback result list<NJY_SysDataModel>
- (void)sendSysHourKcalData:(NJYAsyncCallback *)callback;

/// 联系人 付款码
/// @param model 付款Model
/// @param callback callback  result = 0,成功
-(void)sendFriendeceiptCode:(NJY_AReceiptCodeModel*)model callback:(NJYAsyncCallback *)callback;

/// 同步24小时心率
/// @param callback callback result list<NJY_SysDataModel*> //30分钟一次
- (void)sendSysHourHeartrateData:(NJYAsyncCallback *)callback;

/// 同步24小时血压
/// @param callback callback result list<NJY_SysDataModel*> //30分钟一次
- (void)sendSysHourBloodData:(NJYAsyncCallback *)callback;

/// 同步24小时血氧
/// @param callback callback result list<NJY_SysDataModel*> //30分钟一次
- (void)sendSysHourBloodRaiseData:(NJYAsyncCallback *)callback;

/// 同步消息通知
/// @param callback callback result NJY_NotifModel
-(void) getNotifcations:(NJYAsyncCallback *)callback;

/// 读取适配号
/// @param callback callback result result NSString
-(void)getBindedDeviceInfo:(NJYAsyncCallback *)callback;

/// 开启心电
/// @param type ：1：开始 0：停止
/// @param callback callback result NJY_EcgModel
-(void)getDeviceEcg:(NSInteger)type callback:(NJYAsyncCallback *)callback;

/// 获取版本
/// @param callback callback result 字符串版本
-(void)getDeviceVer:(NJYAsyncCallback *)callback;

/// 获取设备信息
/// @param callback callback result NJY_DeviceConfigModel
-(void)getDeviceConfig:(NJYAsyncCallback *)callback;

/// 获取电量
/// @param callback callback result NSInteger
-(void) getDeviceBat:(NJYAsyncCallback *)callback;

/// BLE蓝牙状态
/// @param callback callback description
-(void) getCentralManagerDidUpdateState:(NJYAsyncCallback *)callback;

/// 获取亮屏状态
/// @param callback callback description
-(void) getDisplayInfo:(NJYAsyncCallback *)callback;

/// 获取固件信息
/// @param callback NJY_DeviceFunModel
-(void) getDeviceFun:(NJYAsyncCallback *)callback;

/// 设置吃药提醒
/// @param model model description
-(void)sendTypeMedic:(NJY_TypeMedicModel*)model;

/// 获取吃药提醒
/// @param callback NJY_TypeMedicModel
-(void)getTypeMedic:(NJYAsyncCallback *)callback;

@end
NS_ASSUME_NONNULL_END

